/**
 * Created by oureda on 4/23/16.
 */
var config = require("../config");
var fs = require("fs");

var Sequelize = require("sequelize");
console.log(config.db.toString());
var sequelize = new Sequelize(
    config.db.toString(),{
        logging:()=>{

        }
    });

fs
    .readdirSync(__dirname)
    .filter(function(item){
        return item !== "migrate.js" && item !== "index.js" && item.indexOf(".") !== 0;
    }).forEach(function(item){
        sequelize.import(item);
    });

var models = sequelize.models;
Object.keys(models).forEach(function(key){
    if(models[key].options.hasOwnProperty("associate")){
        models[key].options.associate(models);
    }
});

module.exports = sequelize;